import os
from PIL import Image

dir_path = r"D:\0_快速保存"
gif_files = []  # 用来存储gif文件路径的列表

# 获取指定目录下的所有gif文件路径
for file_name in os.listdir(dir_path):
    if file_name.endswith('.gif'):
        gif_path = os.path.join(dir_path, file_name)
        gif_files.append(gif_path)

# 遍历gif文件列表，获取每个文件的帧数并输出
for gif_path in gif_files:
    with Image.open(gif_path) as im:
        frames = im.n_frames
        print("{}帧，{}".format(frames, os.path.basename(gif_path)))
